﻿using Common;
using Linguist.Acoustic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linguist.LexTree
{
    public class EndNode: UnitNode
    {
        IUnit baseUnit;
        IUnit leftContext;
        int key;


        /**
        /// Creates the node, wrapping the given hmm
         *
        /// @param baseUnit    the base unit for this node
        /// @param lc          the left context
        /// @param probablilty the probability for the transition to this node
         */
        public EndNode(IUnit baseUnit, IUnit lc, float probablilty) 
            :base(probablilty)
        {
            this.baseUnit = baseUnit;
            this.leftContext = lc;
            key = baseUnit.getBaseID()* 121 + leftContext.getBaseID();
        }


        /**
        /// Returns the base unit for this hmm node
         *
        /// @return the base unit
         */
        override
        public IUnit getBaseUnit() 
        {
            return baseUnit;
        }


        /**
        /// Returns the base unit for this hmm node
         *
        /// @return the base unit
         */
        public IUnit getLeftContext() {
            return leftContext;
        }


        override
        public Object getKey() 
        {
            return key;
        }


        override
        public HMMPosition getPosition() 
        {
            return HMMPosition.END;
        }


        /**
        /// Returns a string representation for this object
         *
        /// @return a string representation
         */
        override
        public String ToString() 
        {
            return "EndNode base:" + baseUnit + " lc " + leftContext + ' ' + key;
        }


        /** Freeze this node. Convert the set into an array to reduce memory overhead */
        public void freeze() 
        {
            base.freeze();
        }
    }
}
